package com.dada.domain.admin;

import com.dada.repository.TableConstants;
import com.dada.test.domain.tables.pojos.Admin;
import lombok.Data;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;
import org.springframework.validation.annotation.Validated;

import javax.validation.constraints.NotNull;
import java.util.List;
import java.util.stream.Collectors;

/**
 * Created by jianweilin on 16/9/5.
 */
@Data
@Component
@Validated
public class AdminInfo implements TableConstants {
    private String username;
    private String password;
    private String nickName;
    private String address;

    public AdminInfo toEntiry(@NotNull Admin admin){
        AdminInfo adminInfo = new AdminInfo();
        BeanUtils.copyProperties(admin,adminInfo);
        adminInfo.setNickName(admin.getNickName());
        return adminInfo;
    }

    public List<AdminInfo> toInfoList(@NotNull List<Admin> admins){
       return admins.stream().map((Admin admin) -> toEntiry(admin)).collect(Collectors.toList());
    }
}
